package com.ewhale.feitengguest.ui.shop.task.adapter

import androidx.recyclerview.widget.RecyclerView
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.databinding.ItemShopTaskBinding
import com.ewhale.feitengguest.dto.ShopTaskDto
import com.simga.library.adapter.BindRecycAdapter
import com.simga.library.utils.glide.GlideUtil

class STaskAdapter : BindRecycAdapter<ItemShopTaskBinding, ShopTaskDto>() {
    var currentTab = 0
    override fun onBindViewHolder(mBinding: ItemShopTaskBinding, itemData: ShopTaskDto, holder: RecyclerView.ViewHolder, position: Int) {
        mBinding.itemData = itemData
        mBinding.currentTab = currentTab
        GlideUtil.loadPicture(itemData.img, mBinding.ivCover, R.drawable.default_image)
        mBinding.tv1.text = "待处理" + itemData.waitHandleNum + "人"
        mBinding.tv2.text = "不及格" + itemData.failNum + "人"
        mBinding.tv3.text = "已完成" + itemData.finishNum + "人"
        mBinding.tvStatus.text = when (currentTab) {
            0 -> {
                if (itemData.frozenStatus == 1) {
                    "已冻结"
                } else {
                    "进行中"
                }
            }
            1 -> "暂停中"
            2 -> "待审核"
            3 -> "不通过"
            else -> "已结束"
        }

        mBinding.btnPause.setOnClickListener { suspend.invoke(position) }
        mBinding.btnEdit.setOnClickListener { edit.invoke(position) }
        mBinding.btnOpen.setOnClickListener { start.invoke(position) }
        mBinding.btnMakeup.setOnClickListener { increasePrice.invoke(position, itemData) }
        mBinding.btnAdd.setOnClickListener { IncreaseQuota.invoke(position, itemData) }
        mBinding.btnDelete.setOnClickListener { delete.invoke(position) }
        mBinding.btnClose.setOnClickListener { taskEnd.invoke(position) }
    }

    override fun normalViewId(): Int {
        return R.layout.item_shop_task
    }

    var suspend: (position: Int) -> Unit = {}//暂停
    var edit: (position: Int) -> Unit = {}//编辑
    var start: (position: Int) -> Unit = {}//开启
    var increasePrice: (position: Int, item: ShopTaskDto) -> Unit = { position: Int, item: ShopTaskDto -> }//涨价
    var IncreaseQuota: (position: Int, item: ShopTaskDto) -> Unit = { position: Int, item: ShopTaskDto -> }//增加名额
    var delete: (position: Int) -> Unit = {}//删除
    var taskEnd: (position: Int) -> Unit = {}//结束
}
